<div class="layui-form-item">
    <label class="layui-form-label">分类名称</label>
    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="title" placeholder="请输入分类名称" class="layui-input title">
    </div>
</div>
<!--<div class="layui-form-item">-->
<!--    <label class="layui-form-label">分类图标</label>-->
<!--    <div class="layui-input-block">-->
<!--        <button type="button" class="layui-btn" id="test1">-->
<!--            <i class="layui-icon">&#xe67c;</i>上传图标-->
<!--        </button>-->
<!--        <input type="text" name="" class="wenzi1" style="width:400px;height:35px;margin-left:20px;display:none;">-->
<!--        <span class="up1" style="width:300px;height:35px;margin-left:20px;display:none;color:red;"></span>-->
<!--        <input type="hidden" value="" class="icon1">-->
<!--        <br><br>-->
<!--        <div style="border:1px solid gainsboro;width:100px;height: 100px;">-->
<!--            <img src="" class="test1" style="height:100px;width:100px;">-->
<!--        </div>-->
<!--    </div>-->
<!--</div>-->
<!--<div class="layui-form-item">-->
<!--    <label class="layui-form-label">分类未选中图标</label>-->
<!--    <div class="layui-input-block">-->
<!--        <button type="button" class="layui-btn" id="test2">-->
<!--            <i class="layui-icon">&#xe67c;</i>上传图标-->
<!--        </button>-->
<!--        <input type="text" name="" class="wenzi2" style="width:400px;height:35px;margin-left:20px;display:none;">-->
<!--        <span class="up2" style="width:300px;height:35px;margin-left:20px;display:none;color:red;"></span>-->
<!--        <input type="hidden" value="" class="icon2">-->
<!--        <br><br>-->
<!--        <div style="border:1px solid gainsboro;width:100px;height: 100px;">-->
<!--            <img src="" class="test2" style="height:100px;width:100px;">-->
<!--        </div>-->
<!--    </div>-->
<!--</div>-->
<div class="layui-form-item">
    <label class="layui-form-label"></label>
    <div class="layui-input-block">
        <button class="layui-btn save">保存</button>
        <button class="layui-btn back">返回</button>
    </div>
</div>




<script>
    //保存
    $('.save').click(function(){
        var title=$('.title').val();
        var icon1=$('.icon1').val();
        var icon2=$('.icon2').val();
        var a=[title,icon1,icon2]
        $.ajax({
            type: "post",
            data: {title:title,icon1:icon1,icon2:icon2},
            dataType: "json",
            url: "<?=base_url("no_edit/sticker/save_add_sticker_type")?>",
            success: function (res) {
                if(res.code==0){
                    layer.msg(res.msg, {time: 2000},function(){
                        window.location.href="<?=base_url("no_edit/sticker/index")?>"
                    });
                }else{
                    layer.msg(res.msg, {time: 2000});
                }
            }
        })
    })
    //返回
    $(".back").click(function(){
        history.go(-1)
    })
    $(function(){
        layui.use('upload', function(){
            var upload = layui.upload;

            //上传图标
            var uploadInst = upload.render({
                elem: '#test1' //绑定元素
                ,url: "<?=base_url("common/upload/normal_upload")?>" //上传接口
                , data: {type: "image"}
                ,acceptMime: 'image/*'
                ,size:"1024"
                , before: function () {
                    $(".up1").text("上传中。。。请等待");
                    $(".up1").show()
                }
                , done: function (res) {
                    if (res.code == 0) {
                        $('.up1').hide();
                        $('.icon1').val(res.data.file_url);
                        $('.wenzi1').val(res.data.file_url);
                        $('.wenzi1').show();
                        $('.test1').attr("src",res.data.file_url);
                        layer.msg(res.msg, {time: 2000});
                    }else{
                        layer.msg(res.msg, {time: 2000});
                    }
                }
            });
            //上传未选中图标
            var uploadInst = upload.render({
                elem: '#test2' //绑定元素
                ,url: "<?=base_url("common/upload/normal_upload")?>" //上传接口
                , data: {type: "image"}
                ,acceptMime: 'image/*'
                ,size:"1024"
                , before: function () {
                    $(".up2").text("上传中。。。请等待");
                    $(".up2").show()
                }
                , done: function (res) {
                    if (res.code == 0) {
                        $('.up2').hide();
                        $('.icon2').val(res.data.file_url);
                        $('.wenzi2').val(res.data.file_url);
                        $('.wenzi2').show();
                        $('.test2').attr("src",res.data.file_url);
                        layer.msg(res.msg, {time: 2000});
                    }else{
                        layer.msg(res.msg, {time: 2000});
                    }
                }
            });
        });
    })

</script>